package com.kd.crawler.dao;

import com.kd.crawler.common.utils.StringUtils;
import com.kd.crawler.entity.Document;

public class AnalyzerDetailsDao extends BaseDao {

	private static final AnalyzerDetailsDao instance = new AnalyzerDetailsDao();
	
	private AnalyzerDetailsDao() {
		
	}
	
	public static AnalyzerDetailsDao getInstance() {
		return instance;
	}
	
	public int insert(Document doc, int originalHtmlId, String analyzerFlag, int spentTime) {
		String sql = "insert tb_analyse_details(oh_id, title_success, date_success, author_success, content_success, analyzer_flag, spent_time) values(?, ?, ?, ?, ?, ?, ?)";
		int titleSuccess = 1;
		int dateSuccess = 1;
		int authorSuccess = 1;
		int contentSuccess = 1;
		if(StringUtils.isBlank(doc.getTitle())) {
			titleSuccess = 0;
		}
		if(null ==doc.getDate()) {
			dateSuccess = 0;
		}
		if(StringUtils.isBlank(doc.getAuthor())) {
			authorSuccess = 0;
		}
		if(StringUtils.isBlank(doc.getContent())) {
			contentSuccess = 0;
		}
		try {
			return this.update(sql, originalHtmlId, titleSuccess, dateSuccess, authorSuccess, contentSuccess, analyzerFlag, spentTime);
		} catch (Exception e) {
			e.printStackTrace();
			return -1;
		}
		
	}
}
